package com.xmall.controller.admin;

import com.xmall.bean.vo.BaseRespVo;
import com.xmall.bean.bo.StorageListBo;
import com.xmall.bean.table.Storage;
import com.xmall.bean.vo.ListDataVo;
import com.xmall.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("admin/storage")
public class StorageController {

    @Autowired
    StorageService storageService;

    @RequestMapping("list")
    public BaseRespVo queryStorageList(StorageListBo storageListBo) {
        if (!storageListBo.isValid()) {
            return BaseRespVo.fail("参数无效，请重新输入");
        }
        ListDataVo<Storage> storageListVo = storageService.queryStorageList(storageListBo);
        return BaseRespVo.ok(storageListVo);
    }

    @PostMapping("create")
    public BaseRespVo createStorage(MultipartFile file) {
        Storage storage = storageService.createStorage(file);
        return BaseRespVo.ok(storage);
    }

    @PostMapping("delete")
    public BaseRespVo deleteStorage(@RequestBody Storage storage) {
        storageService.deleteStorage(storage);
        return BaseRespVo.ok();
    }

    @PostMapping("update")
    public BaseRespVo updateStorage(@RequestBody Storage storage) {
        storageService.updateStorage(storage);
        return BaseRespVo.ok();
    }
}
